package com.lihuinch.test.feishu.eventsubscribe.util;

import com.alibaba.fastjson.JSONObject;
import com.lihuinch.test.feishu.eventsubscribe.constant.FeishuConstant;
import org.springframework.web.client.RestTemplate;


/**
 * @author：岳彩郑
 * @desc：获取飞书自建应用的Token
 * @date：2022/10/8 19:52
 **/

public class GetFeishuToken {

    /**
     * 请求飞书的自建应用的Token
     *
     * @return
     */
    public String getToken() {
        RestTemplate restTemplate = new RestTemplate();
        JSONObject response = new JSONObject();
        response.put("app_id", FeishuConstant.APP_ID);
        response.put("app_secret", FeishuConstant.APP_Secret);
        JSONObject result = restTemplate.postForObject(FeishuConstant.GET_tenant_access_token_URL, response, JSONObject.class);
        String tenant_access_token = result.getString("tenant_access_token");
        return tenant_access_token;
    }
}
